package com.zero.seata.web;

import com.zero.seata.service.impl.AccountServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author zero
 * @ClassName AccountController
 * @Description
 * @Date 2025/5/15 13:37
 */
@RestController
@RequestMapping ("account")
public class AccountController {
    @Value("${spring.application.name}")
    private String appName;
    @Value("${server.port}")
    private String port;
    private AccountServiceImpl accountService;
    public AccountController(AccountServiceImpl accountService) {
        this.accountService = accountService;
    }

    /**
     *
     *  扣减
     * @param userId
     * @param money
     */
    @PostMapping("deduct/{userId}/{money}")
    public void deduct(@PathVariable("userId") String userId, @PathVariable( "money") int money) {
        accountService.deduct(userId, money);
    }

    /**
     * 退款
     * @param userId
     * @param money
     */
     @PostMapping("refund/{userId}/{money}")
     public void refund(@PathVariable("userId") String userId, @PathVariable( "money") int money) {
        accountService.refund(userId, money);
    }


    /**
     *  测试负载均衡
     */
     @GetMapping("loadBalance")
     public String loadBalance() {
          return String.format( "appName:%s,port:%s", appName, port);
     }
}
